package com.ruoyi.app.controller;

import com.ruoyi.system.domain.TBanner;
import com.ruoyi.system.domain.TGoods;
import com.ruoyi.system.domain.TGoodsType;
import com.ruoyi.system.service.ITGoodsService;
import com.ruoyi.system.service.ITGoodsTypeService;
import com.ruoyi.utils.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "小程序端-商品")
@RestController
@RequestMapping("/app/goods")
public class GoodsTypeController {

    @Autowired
    private ITGoodsTypeService tGoodsTypeService;
    @Autowired
    private ITGoodsService tGoodsService;

    @ApiOperation("获取商品类型列表")
    @PostMapping("/getAllGoodsType")
    public AjaxResult<TGoodsType> getAllGoodsType() {
        List<TGoodsType> list =  tGoodsTypeService.selectTGoodsTypeList(null);
        return AjaxResult.success(list);
    }

    @ApiOperation("根据商品类型获取商品列表")
    @GetMapping("/getGoodsByType/{goodTypeId}")
    public AjaxResult<TGoods> getGoodsByType(@PathVariable("goodTypeId") Integer goodTypeId) {
        TGoods tGoods = new TGoods();
        tGoods.setGoodTypeId(goodTypeId);
        tGoods.setIsGrounding(1);
        List<TGoods> list =  tGoodsService.selectTGoodsList(tGoods);
        return AjaxResult.success(list);
    }

    @ApiOperation("根据商品Id获取商品详情")
    @GetMapping("/getGoodsById/{id}")
    public AjaxResult<TGoods> getGoodsByType(@PathVariable("id") Long id) {
        TGoods tGoods =  tGoodsService.selectTGoodsById(id);
        return AjaxResult.success(tGoods);
    }

    @ApiOperation("首页全部商品获取")
    @PostMapping("/getAllGoods")
    public AjaxResult<TGoods> getAllGoods(TGoods tGoods) {
        tGoods.setIsGrounding(1);
        List<TGoods> list =  tGoodsService.selectTGoodsList(tGoods);
        return AjaxResult.success(list);
    }

    @ApiOperation("首页馆长推荐商品获取")
    @PostMapping("/getRecommendedGoods")
    public AjaxResult<TGoods> getRecommendedGoods(TGoods tGoods) {
        tGoods.setIsGrounding(1);
        tGoods.setRecommended(1);
        List<TGoods> list =  tGoodsService.selectTGoodsList(tGoods);
        return AjaxResult.success(list);
    }

    @ApiOperation("首页超大折扣商品获取")
    @PostMapping("/getDiscountGoods")
    public AjaxResult<TGoods> getDiscountGoods(TGoods tGoods) {
        tGoods.setIsGrounding(1);
        List<TGoods> list =  tGoodsService.selectTGoodsList(tGoods);
        return AjaxResult.success(list);
    }

    @ApiOperation("首页最大销量商品获取")
    @PostMapping("/getSalesGoods")
    public AjaxResult<TGoods> getSalesGoods(TGoods tGoods) {
        tGoods.setIsGrounding(1);
        tGoods.setIsHotSales(1);
        List<TGoods> list =  tGoodsService.selectTGoodsList(tGoods);
        return AjaxResult.success(list);
    }
}
